package com.example.easymorse;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class MessageView extends View {

	private String message = "";
	private Paint p;
	
	public MessageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		p = new Paint();
		TypedArray a = context.getTheme().obtainStyledAttributes(
		        attrs,
		        R.styleable.MessageView,
		        0, 0);

		try {
			message = a.getString(R.styleable.MessageView_message);
		} finally {
			a.recycle();
		}
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		message = "touched";
		return super.onTouchEvent(event);
	}
	
	public MessageView(Context context, String msg) {
		super(context);
		message = msg;
		p = new Paint();
	}
	
	@Override
	public void onDraw(Canvas canvas) {
		p.setTextSize(18);
		p.setColor(Color.BLUE);
		p.setAlpha(30);
		canvas.drawRect(2, 2, getWidth()-2, getHeight()-3, p);
		
		p.setColor(Color.BLACK);
		canvas.drawText(message, 20, 23, p);
		
	}
	
	@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
		setMeasuredDimension(400,35);
    }
	
}
